package com.sky.controller.user;

import com.sky.constant.MessageConstant;
import com.sky.entity.Category;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("userCategoryController")
@RequestMapping("/user/category")
@Api(tags = "C端-分类接口")
@Slf4j
public class CategoryController {
    private final CategoryService categoryService;

    @Autowired
    public CategoryController(CategoryService categoryService) {
        this.categoryService = categoryService;
    }


    /**
     * @param type 分类类型：1 菜品分类 2 套餐分类
     * @return 某个菜品分类下的所有分类
     */
    @GetMapping("/list")
    @ApiOperation("C端分类列表")
    public Result<List<Category>> list(Integer type) {
        log.info("C端分类列表:{}", type);
        return Result.success(categoryService.list(type), MessageConstant.SELECT_OK);
    }
}
